package models

type Comment struct {
	ID        int    `gorm:"primary_key" json:"id"`
	OwnerId   string `json:"owner_id"`
	Text      string `json:"text"`
	ArticleId int    `json:"article_id"`
}

func SelectComment(maps interface{}) (comments []Comment) {
	db.Where(maps).Find(&comments)
	return comments
}

func InsertComment(maps map[string]interface{}) error {
	comment := Comment{
		OwnerId:   maps["OwnerId"].(string),
		Text:      maps["Text"].(string),
		ArticleId: maps["ArticleId"].(int),
	}

	if err := db.Model(&Comment{}).Create(&comment).Error; err != nil {
		return err
	}
	return nil
}

func DelComment(id int) error {
	if err := db.Where("id = ?", id).Delete(&Comment{}).Error; err != nil {
		return err
	}
	return nil
}
